package com.edu.bean;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Repository;
import org.springframework.stereotype.Service;

/**
 * @Author:mx
 * @Date :2022/10/27 - 10 - 27 - 16:28
 */

/*
*
*       @Component  通用
*       @Controller  用于控制层
*       @Service     用于业务逻辑层
*       @Repository  用于数据访问层
*           这些注解放在类的上面，表示标注的类 被Spring容器管理，默认的id是 类名(首字母小写)
*           @Component("别名") 可以改变 bean的Id
*
*       @Scope 设置作用域 singleton 单例
*                        prototype 多利
* */

@Component("myuser")
/*@Scope("prototype")*/
public class User {

//    @Value("1")
    private int userId;

    private String username;


//    @Value("${user.password}")
    private String password;

    public int getUserId() {
        return userId;
    }

    public void setUserId(int userId) {
        this.userId = userId;
    }

    public String getUsername() {
        return username;
    }

//    @Value("zhangsan")
    public void setUsername(String username)
    {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    @Override
    public String toString() {
        return "User{" +
                "userId=" + userId +
                ", username='" + username + '\'' +
                ", password='" + password + '\'' +
                '}';
    }


    public User(@Value("2") int userId, @Value("lisi") String username,@Value("helloworld") String password) {
        this.userId = userId;
        this.username = username;
        this.password = password;
    }
}
